package com.lishe.lishe.lishe.MyRecyclerView;

import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

/**
 * Created by shino on 2017/9/28.
 */

public class RecyclerLinearViewItemDecoration extends RecyclerView.ItemDecoration {
    int headerCount;
    int foorderCount;
    int space;//间隔
    boolean isPadingHeader = false;

    public RecyclerLinearViewItemDecoration(int space, boolean isPadingHeader) {
        this.space = space;
        this.isPadingHeader = isPadingHeader;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int position = parent.getChildAdapterPosition(view);
        LinearLayoutManager manager = (LinearLayoutManager) parent.getLayoutManager();
        int type = parent.getAdapter().getItemViewType(position);
        if (manager instanceof LinearLayoutManager) {
            if (manager.getOrientation() == LinearLayout.HORIZONTAL) {
                if (isPadingHeader) {
                    if (type != RecyclerviewBaseAdapter.TYPE_FOOTER &&
                            type != RecyclerviewBaseAdapter.TYPE_REFRESH_FOOTER && type != RecyclerviewBaseAdapter.TYPE_REFRESH_HEADER) {//暂时不兼容存在footview
                        outRect.right = space;
                    }
                } else {
                    if (type != RecyclerviewBaseAdapter.TYPE_FOOTER && type != RecyclerviewBaseAdapter.TYPE_HEADER &&
                            type != RecyclerviewBaseAdapter.TYPE_REFRESH_FOOTER && type != RecyclerviewBaseAdapter.TYPE_REFRESH_HEADER) {//暂时不兼容存在footview
                        outRect.right = space;
                    }
                }
            } else if (manager.getOrientation() == LinearLayout.VERTICAL) {
                if (isPadingHeader) {
                    if (type != RecyclerviewBaseAdapter.TYPE_FOOTER &&
                            type != RecyclerviewBaseAdapter.TYPE_REFRESH_FOOTER && type != RecyclerviewBaseAdapter.TYPE_REFRESH_HEADER) {//暂时不兼容存在footview
                        outRect.bottom = space;
                    }
                } else {
                    if (type != RecyclerviewBaseAdapter.TYPE_FOOTER && type != RecyclerviewBaseAdapter.TYPE_HEADER &&
                            type != RecyclerviewBaseAdapter.TYPE_REFRESH_FOOTER && type != RecyclerviewBaseAdapter.TYPE_REFRESH_HEADER) {//暂时不兼容存在footview
                        outRect.bottom = space;
                    }
                }
            }
        }
    }
}
